package sound;


public class Utils {


	private static String[] SongList = {
		"resources/music-A.wav",
		"resources/music-B.wav",
		"resources/music-C.wav"
	};
	
	public static String homeMenuTone = "resources/tetris-title.wav";
	public static String gameBackgroundTone = getRandomBackgroundSong();
	public static String gameOverTone	= "resources/game-over.wav";
	public static String scorePanelTone = "resources/high-score.wav";
	public static String soundNextLevel = "resources/next-level.wav";
	public static String soundFourLines = "resources/four-lines.wav";
	public static String soundFixedBlock = "resources/fixed.wav";
	public static String soundRemoveCompletedLine = "resources/removedLines.wav";
	
	
	public static String[] getSongList(){
		String[] returned = new String[SongList.length];

		for(int i=0;i< SongList.length; i++){		
			returned[i] = SongList[i];
		}
		return returned;
	}

	/*
	@Deprecated : la longueur de la musique est calculé automatiquement
	public static int getDuration(String pPathSong){
		Integer tmp;
		int returned = 0;

		for(int i=0;i< SongListTimed.length; i++){		
			if(SongListTimed[i][0].equals(pPathSong)){
				tmp = Integer.valueOf(SongListTimed[i][1]);
				returned = tmp.intValue();
			}
		}
		return returned;
	}
	*/

	/**
	 * 
	 * @param pIndex : Si négatif, retournera la première chanson, si trop grand la dernière chanson de la liste
	 * @return 
	 */
	public static String getSong(int pIndex){
		String returned ="";

		while(returned.equals("")){
			if(pIndex >=0 && pIndex < SongList.length){		
				returned = SongList[pIndex];
			}
			if(pIndex>0){
				pIndex--;
			}
			else{
				pIndex++;
			}
		}
		return returned;
	}
	
	public static String getRandomSong(){
		double rnd = Math.random();
		
		int nbSong = getNbSong();
		float result =  (float) (rnd*nbSong);
		return getSong((int)result);
	}
	
	
	public static String getRandomBackgroundSong(){
		String returned = getRandomSong();
		gameBackgroundTone = returned;
		return returned;
	}
	
	
	public static int getNbSong(){
		return SongList.length;
	}
	
	
}